﻿/*****************************************************************
 *@Copyright all rights reserved © 2014 Yuga
 *@author YUga studio
 *Contact: zengkang007@gmail.com
 *****************************************************************/
package com.oplink.webbase.modules.invoicing.service;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.oplink.webbase.common.persistence.Page;
import com.oplink.webbase.modules.invoicing.entity.ReturnOrder;
import com.oplink.webbase.modules.invoicing.dao.ReturnOrderDao;



/**
 * 告警Service
 * @author YUga studio
 * @version 2015-01-12
 */
@Component
@Transactional
public class ReturnOrderService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(ReturnOrderService.class);
	
	@Autowired
	private ReturnOrderDao returnOrderDao;
	
	public ReturnOrder get(Long id) {
		return returnOrderDao.findOne(id);
	}
	
	public Page<ReturnOrder> find(Page<ReturnOrder> page, ReturnOrder returnOrder) {
		DetachedCriteria dc = returnOrderDao.createDetachedCriteria();
		//添加查询条件
		if (null != returnOrder.getReturnFormId()
				&& StringUtils.isNotEmpty(returnOrder.getReturnFormId().toString())) {
			dc.add(Restrictions.like("returnFormId", "%"+returnOrder.getReturnFormId()+"%"));
		}
		if (null != returnOrder.getOperatman()
				&& StringUtils.isNotEmpty(returnOrder.getOperatman().toString())) {
			dc.add(Restrictions.like("operatman", "%"+returnOrder.getOperatman()+"%"));
		}
		dc.add(Restrictions.eq(ReturnOrder.DEL_FLAG, ReturnOrder.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return returnOrderDao.find(page, dc);
	}
	
	/**
	  * @function 创建查询
	  **/
	public Page<ReturnOrder> getUserReturnOrder(Page<ReturnOrder> page, ReturnOrder returnOrder) {
		DetachedCriteria dc = returnOrderDao.createDetachedCriteria();
		//添加查询条件
		if (null != returnOrder.getReturnFormId()
				&& StringUtils.isNotEmpty(returnOrder.getReturnFormId().toString())) {
			dc.add(Restrictions.like("returnFormId", "%"+returnOrder.getReturnFormId()+"%"));
		}
		if (null != returnOrder.getOperatman()
				&& StringUtils.isNotEmpty(returnOrder.getOperatman().toString())) {
			dc.add(Restrictions.like("operatman", "%"+returnOrder.getOperatman()+"%"));
		}
		dc.add(Restrictions.eq(ReturnOrder.DEL_FLAG, ReturnOrder.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return returnOrderDao.find(page, dc);
	}
	
	public ReturnOrder getReturnOrder(Long id) {
		return returnOrderDao.findOne(id);
	}

	public void saveReturnOrder(ReturnOrder entity) {
		returnOrderDao.save(entity);
	}
	
	public void deleteReturnOrder(Long id) {
		returnOrderDao.delete(id);
	}
	
	@Autowired
	public void setReturnOrderDao(ReturnOrderDao returnOrderDao) {
		this.returnOrderDao = returnOrderDao;
	}	
}
